function intTochartDataCSV(powerInt){
    dataArray = new Array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9","-",".");
    
    var xxx = Math.floor(powerInt / 64);
    var yyy = powerInt % 64;
    
    var chartchar = dataArray[xxx]+dataArray[yyy];
   
    return chartchar;
}


function csvGetter(){
    $.ajax({
           url:"http://ubicsmartgrid.appspot.com/ubicsmartgrid",
           success:function(csv){
	   //console.log(csv);
	   var csvSeparate=csv.split("\n");
	   //console.log(csvSeparate.length);
           var url ="<img src=\"http://chart.apis.google.com/chart?cht=bvs&chs=1000x300&chg=20,10,1,30&chd=e:"
           var xdim = "";

           for(i=csvSeparate.length-2 ;i>=0 ;i--){
           //console.log(csvSeparate[i]);
           var csvSeparateWithTIMEandPOWER = csvSeparate[i].split(",");
	   //console.log(csvSeparateWithTIMEandPOWER[0]);
    	   //console.log(csvSeparateWithTIMEandPOWER[1]);
            
	    var csvSeparateWithTIME = csvSeparateWithTIMEandPOWER[0].split(" ");
            var HOURMINUTESECOND = csvSeparateWithTIME[3].split(":");
           //時刻を求める
            var HOUR = HOURMINUTESECOND[0];
           
            var csvSeparateWithPOWER = csvSeparateWithTIMEandPOWER[1].split("=");
           //電力を求める
            var POWER = csvSeparateWithPOWER[1];
           

           //x軸となる時間の文字列を足し合わせて行く
            xdim += HOUR + "|";
            //整数データに変換
            var powerInt = parseInt(POWER);
            
            //グラフのために微調整。ここは要改善
            powerInt = parseInt(powerInt*2.9);
            //e:の企画に合うように数字を文字列に変換
            var chartchar = intTochartDataCSV(powerInt);
            
            //プロット
            
            if(i > 0 ){ 
            url += chartchar;
            }
            else{
            url += chartchar+",";
            } 
           
            }
            url+= "&chxt=x,y&chxl=0:|"+xdim+"1:|0|200|400|600|800|1000|1200|1400";
            //urlの最終情報補完
            var Today = "";
            var date = new Date();
            
            Today += "Date:"+(date.getMonth()+1)+"/"+date.getDate();
            url +="&chco=FFC266&chtt="+Today+"&chm=D,FF9900,0,0,3,1\"/>";
           
           $("#csvdata").append(url);
            
           }
        });
    
}